﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FACUI.BasicClass
{
    public class MapLinkRelation
    {
        public List<Quduan> allQuduan;
        public int iDingfanSort;
        public int iPosSortBy;
        public int iQuduanLeftNo;
        public int iQuduanNo;
        public int iQuduanRightNo;
        public List<bool> lst定反表;

        public MapLinkRelation(List<Quduan> allQuduan, int iPosSortBy, int iQuduanNo, int iQuduanLeftNo, int iQuduanRightNo, int iDingfanSort)
        {
            this.lst定反表 = new List<bool>();
            this.allQuduan = allQuduan;
            this.iPosSortBy = iPosSortBy;
            this.iQuduanNo = iQuduanNo;
            this.iQuduanLeftNo = iQuduanLeftNo;
            this.iQuduanRightNo = iQuduanRightNo;
            this.lst定反表.Clear();
            this.iDingfanSort = iDingfanSort;
            for (int i = 0; i < iDingfanSort; i++)
            {
                this.lst定反表.Add((((int)Math.Pow(2.0, (double)i)) & iDingfanSort) != 0);
            }
        }

        public MapLinkRelation(List<Quduan> allQuduan, int iPosSortBy, int iQuduanNo, int iQuduanLeftNo, int iQuduanRightNo, int iDingfanSort, List<bool> lst定反表)
        {
            this.lst定反表 = new List<bool>();
            this.allQuduan = allQuduan;
            this.iPosSortBy = iPosSortBy;
            this.iQuduanNo = iQuduanNo;
            this.iQuduanLeftNo = iQuduanLeftNo;
            this.iQuduanRightNo = iQuduanRightNo;
            this.iDingfanSort = iDingfanSort;
            this.lst定反表 = lst定反表;
        }

        public string ToNodeString()
        {
            StringBuilder builder = new StringBuilder("");
            int iQuduanLeftNo = this.iQuduanLeftNo;
            int iQuduanNo = this.iQuduanNo;
            int iQuduanRightNo = this.iQuduanRightNo;
            builder.Append((iQuduanNo != -1) ? this.allQuduan[iQuduanNo].name : "NULL").Append(',').Append((iQuduanLeftNo != -1) ? this.allQuduan[iQuduanLeftNo].name : "NULL").Append(',').Append((iQuduanRightNo != -1) ? this.allQuduan[iQuduanRightNo].name : "NULL").Append(',');
            if ((this.allQuduan[iQuduanNo].lst道岔.Count >= 1) && (this.lst定反表.Count == this.allQuduan[iQuduanNo].lst道岔.Count))
            {
                for (int i = 0; i < this.allQuduan[iQuduanNo].lst道岔.Count; i++)
                {
                    if (this.lst定反表[i])
                    {
                        builder.Append(this.allQuduan[iQuduanNo].lst道岔[i].text).Append(',');
                    }
                    else
                    {
                        builder.Append('(').Append(this.allQuduan[iQuduanNo].lst道岔[i].text).Append(')').Append(',');
                    }
                }
            }
            if ("".Equals(builder.ToString()))
            {
            }
            return builder.ToString();
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("");
            int iQuduanLeftNo = this.iQuduanLeftNo;
            int iQuduanNo = this.iQuduanNo;
            int iQuduanRightNo = this.iQuduanRightNo;
            builder.Append((iQuduanNo != -1) ? this.allQuduan[iQuduanNo].name : "NULL").Append(',').Append((iQuduanLeftNo != -1) ? this.allQuduan[iQuduanLeftNo].name : "NULL").Append(',').Append((iQuduanRightNo != -1) ? this.allQuduan[iQuduanRightNo].name : "NULL").Append(',');
            if ((this.allQuduan[iQuduanNo].lst道岔.Count >= 1) && (this.lst定反表.Count == this.allQuduan[iQuduanNo].lst道岔.Count))
            {
                for (int i = 0; i < this.allQuduan[iQuduanNo].lst道岔.Count; i++)
                {
                    if (this.lst定反表[i])
                    {
                        builder.Append(this.allQuduan[iQuduanNo].lst道岔[i].text).Append(',');
                    }
                    else
                    {
                        builder.Append('(').Append(this.allQuduan[iQuduanNo].lst道岔[i].text).Append(')').Append(',');
                    }
                }
            }
            builder.Append("GAP");
            if ("".Equals(builder.ToString()))
            {
            }
            return builder.ToString();
        }

        public ulong uSort
        {
            get
            {
                return (ulong)((this.iPosSortBy * 0xf4240) + this.iDingfanSort);
            }
        }
    }
    /******************************************************************************/
    public class LinkRelationPoint
    {
        public int dd1;
        public int dd2;
        public int qd1;
        public int qd2;

        public LinkRelationPoint(int qd1, int dd1, int qd2, int dd2)
        {
            this.qd1 = qd1;
            this.qd2 = qd2;
            this.dd1 = dd1;
            this.dd2 = dd2;
        }
    }

}

